#include <iostream>
#include<vector>

using namespace std;

int main()
{
    int n, V;
    cin >> n >> V;
    vector<vector<int>>nums(n, { 0,0 });
    for (int i = 0; i < n; i++)
    {
        cin >> nums[i][0] >> nums[i][1];
    }
    vector<int>dp(V + 1, 0);
    for (int i = 0; i < n; i++)
    {
        for (int j = 1; j < V + 1; j++)
        {
            int sz = j - nums[i][0];
            if (sz == 0)
            {
                dp[j] = max(dp[j], nums[i][1]);
            }
            else if (sz > 0 && dp[sz])
            {
                dp[j] = max(dp[j], dp[sz] + nums[i][1]);
            }

        }
    }
    int number = 0;
    for (auto a : dp)
    {
        number = max(number, a);
    }
    cout << number << endl << dp[V];
    return 0;
}